/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.model.util
{
	public class TimeCode
	{
		private var _showHours:Boolean;
		
		public function TimeCode() 
		{
			_showHours = true;
		}

			
		public function showHours(show:Boolean):void 
		{
			_showHours = show;
		}
		
			
		public function getTC(seconds:Number):String
		{
			if(typeof(seconds) != "number")
				return "00:";
			
			var result:String = "";		
			var myTime:Date = new Date(2007, 0, 1 , 0, 0, seconds);		
				
			// hours
			if (_showHours == true) 
			{
				if (myTime.getHours() <10) 
				{
    				result = "0" + myTime.getHours() + ":";
				}
				else 
				{
    				result = myTime.getHours() + ":";
   				}
			}
			
			// minutes
			if (myTime.getMinutes() <10) 
			{
        		result += "0" + myTime.getMinutes() + ":";
    		}
    		else 
    		{
        		result += myTime.getMinutes() + ":";
   			}			
			
			// seconds
			if (myTime.getSeconds() <10) 
			{
        		result += "0" + myTime.getSeconds();
    		}
    		else 
    		{
        		result += myTime.getSeconds();
   			}
			
			return result;
		}
		
		public function getTCompressed(seconds:Number):String
		{
			if(typeof(seconds) != "number")
				return "00:";
			
			var result:String = "";		
			var myTime:Date = new Date(2007, 0, 1 , 0, 0, seconds);		
		
				
			// hours
			if (_showHours == true)
			{
				if (myTime.getHours() <10)
				{
					if(myTime.getHours()!=0)
    					result = "0" + myTime.getHours() + ":";
				}
				else
				{
					result = myTime.getHours() + ":";
   				}
			}
			
			// minutes
			if (myTime.getMinutes() <10)
			{
        		result += "0" + myTime.getMinutes() + ":";
    		}
    		else
    		{
        		result += myTime.getMinutes() + ":";
   			}			
			
			// seconds
			if (myTime.getSeconds() <10) 
			{
        		result += "0" + myTime.getSeconds();
    		}
    		else 
    		{
        		result += myTime.getSeconds();
   			}
			return result;
		}
	}
}